
package com.dotools;

import com.dotools.base.CommonConstants;
import com.dotools.debug.LOG;
import com.dotools.utils.DevicesUtils;

import android.graphics.Bitmap;
import android.graphics.Canvas;

// could not be proguarded, use simple method name
public class Native {
    static boolean loadSuccess;

    static {
        try {
            System.loadLibrary("common");
            loadSuccess = true;
        } catch (Throwable tr) {
            loadSuccess = false;
            if (CommonConstants.IS_DEBUG) {
                LOG.logE("could not load library", tr);
                LOG.logE("----------------------------------------------------------"
                        + DevicesUtils.getDeviceDescription());
                LOG.logE("----------------------------------------------------------");
            }
        }
    }

    public static void gingerBlur(Bitmap bmpToBlur, int radius) {
        if (loadSuccess) {
            a(bmpToBlur, radius);
        } else {
            fakeBlur(bmpToBlur);
        }
    }
    private static native void a(Bitmap bmp, int repeat);

    public static void simpleBlur(Bitmap bmpToBlur, int radius) {
        if (loadSuccess) {
            b(bmpToBlur, radius);
        } else {
            fakeBlur(bmpToBlur);
        }
    }
    private static native void b(Bitmap origBitmap, int radius);

    public static void stackBlur(Bitmap bmpToBlur, int radius) {
        if (loadSuccess) {
            c(bmpToBlur, radius);
        } else {
            fakeBlur(bmpToBlur);
        }
    }
    private static native void c(Bitmap origBitmap, int radius);

    private static void fakeBlur(Bitmap origBitmap) {
        Canvas c = new Canvas(origBitmap);
        c.drawColor(0x80000000);
    }
}
